package de.gbeine.java.depview.ui.component;

import java.util.Enumeration;

import javax.swing.JEditorPane;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.PlainDocument;
import javax.swing.text.html.HTMLDocument;

import com.google.common.eventbus.EventBus;
import com.jgoodies.forms.factories.FormFactory;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.RowSpec;

import de.gbeine.java.depview.model.Element;

/**
 *
 * @author gbeine
 *
 */
public final class InformationPanel extends JPanel implements de.gbeine.java.depview.ui.controller.InformationPanel {

    private final JEditorPane editorPane;

    /**
     *
     */
    private final EventBus eventBus;

    /**
     * Create the panel.
     */
    public InformationPanel(final EventBus pEventBus) {
        super();
        this.eventBus = pEventBus;
        setLayout(new FormLayout(new ColumnSpec[] {
                FormFactory.RELATED_GAP_COLSPEC,
                ColumnSpec.decode("default:grow"),
                FormFactory.RELATED_GAP_COLSPEC,
                FormFactory.LABEL_COMPONENT_GAP_COLSPEC,},
            new RowSpec[] {
                FormFactory.RELATED_GAP_ROWSPEC,
                FormFactory.DEFAULT_ROWSPEC,
                FormFactory.RELATED_GAP_ROWSPEC,
                RowSpec.decode("100dlu"),
                FormFactory.RELATED_GAP_ROWSPEC,
                FormFactory.DEFAULT_ROWSPEC,
                FormFactory.RELATED_GAP_ROWSPEC,
                FormFactory.NARROW_LINE_GAP_ROWSPEC,}));

        final JLabel lblFilter = new JLabel("Information");
        this.add(lblFilter, "2, 2");

        this.editorPane = new JEditorPane();
        this.editorPane.setEditable(false);
        this.add(this.editorPane, "2, 4, fill, fill");

        Document doc = new PlainDocument();
        try {
            doc.insertString(0, "Hallo Welt", null);
        } catch (BadLocationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        this.editorPane.setDocument(doc);

    }

    @Override
    public void setElement(Element pElement) {
        // TODO: refactor this :-)
        // Should be done by a component outside of the informationpanel
        Document doc = new PlainDocument();
        try {
            doc.insertString(0, pElement.toString(), null);
        } catch (BadLocationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        this.editorPane.setDocument(doc);
    }
}
